<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>管理员管理</el-breadcrumb-item>
      <el-breadcrumb-item>管理员列表</el-breadcrumb-item>
    </el-breadcrumb>
   
    <!-- 卡片视图 -->
    <el-card>
      <h3>管理员列表</h3>
      <!-- 用户列表区域 -->
     <el-select v-model="value" placeholder="请选择" @blur="searchByType(value)">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
   <el-input v-model="input" placeholder="请输入搜索内容" @blur="searchByUsername(input)"></el-input>
  </el-select>
  </el-select>
      <el-table :data="pageData.data" border stripe>
        <el-table-column label="管理员用户名" prop="username">
         
        </el-table-column>
        <el-table-column label="管理员密码" prop="password"></el-table-column>
        <el-table-column label="权限" prop="permission"></el-table-column>
       
        <el-table-column label="操作">
          <template slot-scope="scope">
            
            <el-button size="mini" @click="updateId(scope.row._id)">修改</el-button>
            <el-button size="mini" type="danger" @click="dele(scope.row._id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageData.currentPage-0"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pageData.pageSize-0"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.total"
      ></span>
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers(
  "admin"
);

export default {
  data() {
      return {
       options: [{
          value: 'permission',
          label: '管理员'
        }, {
          value: 'username',
          label: '用户名'
        }, 
        {
          value: 'SuperPermission',
          label: '超级管理员'
        },],
        value: '用户名',
        input: ''
      }
    },
  computed: {
    ...mapState(["pageData"]),
  },
  created() {
    this.getAllAdmins();
    console.log(this.pageData.data)
  },
  methods: {
    ...mapActions(["getAllAdmins","deleteAdminByID"]),
    ...mapMutations(["setPageSize","setCurrent","setSerachDataByusername","setSerachDataBytype"]),
    searchByUsername(val){
      this.value="username"
      this.setSerachDataByusername(val)
        this.getAllAdmins();
    },
    searchByType(val){
              this.setSerachDataBytype(val)
              this.getAllAdmins();
    },
    handleSizeChange(val) {
      this.setPageSize(val);
     this.getAllAdmins();
    },
    handleCurrentChange(val) {
  
      this.setCurrent(val);
      this.getAllAdmins();
    },
    dele(row) {
      // 删除提示框
   
      this.$confirm("此操作将永久删除该管理员, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "danger",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.deleteAdminByID(row);
          this.getAllAdmins();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //修改
    updateId(_id){
          this.$router.push({
                path:'/ModifyAdminIstratorAccount',
                query:{
                      _id
                }
              })
    }
  },
};
</script>

<style>
</style>